﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;
using System.Collections.Generic;//Please add references
namespace EnterpriseFund.DAL
{
    /// <summary>
    /// 数据访问类:TaxAuditPolicyEval
    /// </summary>
    public partial class TaxAuditPolicyEval
    {
        public TaxAuditPolicyEval()
        { }
        #region  BasicMethod

        public void Invalid(Model.TaxAuditPolicyEval model)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("update fund.t_TaxAuditPolicyEval set ");
            strSql.Append("FStatus=@FStatus ");
            strSql.Append(" where FTaxAuditId=@FTaxAuditId and FYear=@FYear and FTaxClassAllowanceNo=@FTaxClassAllowanceNo ");
            SqlParameter[] parameters3 = {
					new SqlParameter("@FStatus", SqlDbType.NVarChar,6),
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50),
                    new SqlParameter("@FYear", SqlDbType.Decimal,4),
					new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,20)};
            parameters3[0].Value = "9";
            parameters3[1].Value = model.FTaxAuditId;
            parameters3[2].Value = model.FYear;
            parameters3[3].Value = model.FTaxClassAllowanceNo;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters3;
            cmdList.Add(cmds);

            if (model.FIssueID != null && model.FIssueID != "")
            {
                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append("delete from fund.t_AllowanceIssueEntry ");
                strSql.Append(" where FIssueID=@FIssueID and FTaxClassAllowanceNo=@FTaxClassAllowanceNo and NSRDZDAH=@NSRDZDAH");
                SqlParameter[] parameters2 = {
					new SqlParameter("@FIssueID", SqlDbType.NVarChar,50)	,	
                    new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,20)	,	
                    new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,20)		};
                parameters2[0].Value = model.FIssueID;
                parameters2[1].Value = model.FTaxClassAllowanceNo;
                parameters2[2].Value = model.NSRDZDAH;
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters2;
                cmdList.Add(cmds);
            }

            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }
        }

        public void Check(Model.AllowanceIssueEntry model)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();
            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("update fund.t_AllowanceIssueEntry set ");
            strSql.Append("FStatus=@FStatus ");
            strSql.Append(" where FAllowanceIssueEntryID=@FAllowanceIssueEntryID ");
            SqlParameter[] parameters4 = {
					new SqlParameter("@FStatus", SqlDbType.NVarChar,6),
					new SqlParameter("@FAllowanceIssueEntryID", SqlDbType.NVarChar,20)};
            parameters4[0].Value = model.FStatus;
            parameters4[1].Value = model.FAllowanceIssueEntryID;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters4;
            cmdList.Add(cmds);
            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }
        }

        public void Compute(Model.TaxAuditPolicyEval model, Model.AllowanceIssueEntry model2,string entryType)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("update fund.t_TaxAuditPolicyEval set ");
            strSql.Append("FStatus=@FStatus,");
            strSql.Append("FIssueID=@FIssueID ");
            strSql.Append(" where FTaxAuditId=@FTaxAuditId and FYear=@FYear and FTaxClassAllowanceNo=@FTaxClassAllowanceNo ");
            SqlParameter[] parameters3 = {
					new SqlParameter("@FStatus", SqlDbType.NVarChar,6),
                    new SqlParameter("@FIssueID", SqlDbType.NVarChar,50),
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50),
                    new SqlParameter("@FYear", SqlDbType.Decimal,4),
					new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,20)};
            parameters3[0].Value = "3";
            parameters3[1].Value = model.FIssueID;
            parameters3[2].Value = model.FTaxAuditId;
            parameters3[3].Value = model.FYear;
            parameters3[4].Value = model.FTaxClassAllowanceNo;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters3;
            cmdList.Add(cmds);

            if (entryType == "Update")
            {
                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append("update fund.t_AllowanceIssueEntry set ");
                strSql.Append("FStatus=1 ,");
                strSql.Append("FFactAllowanceAmt=@FFactAllowanceAmt");
                strSql.Append(" where FIssueID=@FIssueID and FTaxClassAllowanceNo=@FTaxClassAllowanceNo and NSRDZDAH=@NSRDZDAH ");
                SqlParameter[] parameters4 = {
                    new SqlParameter("@FFactAllowanceAmt", SqlDbType.Int,32)	,	
					new SqlParameter("@FIssueID", SqlDbType.NVarChar,50)	,	
                    new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,20)	,	
                    new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,20)	};
                parameters4[0].Value = model2.FFactAllowanceAmt;
                parameters4[1].Value = model2.FIssueID;
                parameters4[2].Value = model2.FTaxClassAllowanceNo;
                parameters4[3].Value = model2.NSRDZDAH;
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters4;
                cmdList.Add(cmds);
            }
            else
            {
                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append("insert into fund.t_AllowanceIssueEntry(");
                strSql.Append("FIssueID,FYear,FTaxClassAllowanceNo,FAllowancePeriodAmt,FAllowanceBalAmt,NSRDZDAH,FFactAllowanceAmt,FStatus)");
                strSql.Append(" values (");
                strSql.Append("@FIssueID,@FYear,@FTaxClassAllowanceNo,@FAllowancePeriodAmt,@FAllowanceBalAmt,@NSRDZDAH,@FFactAllowanceAmt,@FStatus)");
                strSql.Append(";select @@IDENTITY");
                SqlParameter[] parameters2 = {
					new SqlParameter("@FIssueID", SqlDbType.NVarChar,50),
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,20),
					new SqlParameter("@FAllowancePeriodAmt", SqlDbType.Decimal,13),
					new SqlParameter("@FAllowanceBalAmt", SqlDbType.Decimal,13),
					new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,13),
                    new SqlParameter("@FFactAllowanceAmt", SqlDbType.Decimal,13),
                    new SqlParameter("@FStatus", SqlDbType.NVarChar,20)};
                parameters2[0].Value = model2.FIssueID;
                parameters2[1].Value = model2.FYear;
                parameters2[2].Value = model2.FTaxClassAllowanceNo;
                parameters2[3].Value = model2.FAllowancePeriodAmt;
                parameters2[4].Value = model2.FAllowanceBalAmt;
                parameters2[5].Value = model2.NSRDZDAH;
                parameters2[6].Value = model2.FFactAllowanceAmt;
                parameters2[7].Value = model2.FStatus;
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters2;
                cmdList.Add(cmds);
            }

            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void SaveAdd(List<EnterpriseFund.Model.TaxAuditPolicyEval> tAPList,Model.TaxAuditForm tAF)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("update fund.t_TaxAuditForm set ");
            strSql.Append("FStatus=@FStatus,");
            strSql.Append("FPolicyNote=@FPolicyNote,");
            strSql.Append("FNewEnterprisePropNo=@FNewEnterprisePropNo,");
            strSql.Append("FIsReturn=@FIsReturn,");
            strSql.Append("FNewFinancePropNo=@FNewFinancePropNo");
            strSql.Append(" where FTaxAuditId=@FTaxAuditId ");
            SqlParameter[] parameters3 = {
					new SqlParameter("@FStatus", SqlDbType.NVarChar,6),
					new SqlParameter("@FPolicyNote", SqlDbType.NVarChar,255),
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50),
					new SqlParameter("@FNewEnterprisePropNo", SqlDbType.NVarChar,6),
                    new SqlParameter("@FIsReturn", SqlDbType.NVarChar,1),
					new SqlParameter("@FNewFinancePropNo", SqlDbType.NVarChar,6)};
            parameters3[0].Value = tAF.FStatus;
            parameters3[1].Value = tAF.FPolicyNote;
            parameters3[2].Value = tAF.FTaxAuditId;
            parameters3[3].Value = tAF.FNewEnterprisePropNo;
            parameters3[4].Value = tAF.FIsReturn;
            parameters3[5].Value = tAF.FNewFinancePropNo;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters3;
            cmdList.Add(cmds);


            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("delete from fund.t_TaxAuditPolicyEval ");
            strSql.Append(" where FTaxAuditId=@FTaxAuditId ");
            SqlParameter[] parameters2 = {
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50)			};
            parameters2[0].Value = tAF.FTaxAuditId;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters2;
            cmdList.Add(cmds);

            foreach (Model.TaxAuditPolicyEval model in tAPList)
            {
                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append("insert into fund.t_TaxAuditPolicyEval(");
                strSql.Append("FTaxAuditId,FYear,FTaxClassAllowanceNo,FBaseAmount,FAllowanceType,FInnerRate,FOuterRate,FAllowanceAmount,FPolicyID,FIssueID,FFinancePropNo,FStatus)");
                strSql.Append(" values (");
                strSql.Append("@FTaxAuditId,@FYear,@FTaxClassAllowanceNo,@FBaseAmount,@FAllowanceType,@FInnerRate,@FOuterRate,@FAllowanceAmount,@FPolicyID,@FIssueID,@FFinancePropNo,@FStatus)");
                SqlParameter[] parameters = {
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50),
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,20),
					new SqlParameter("@FBaseAmount", SqlDbType.Decimal,13),
					new SqlParameter("@FAllowanceType", SqlDbType.NVarChar,255),
					new SqlParameter("@FInnerRate", SqlDbType.Decimal,5),
					new SqlParameter("@FOuterRate", SqlDbType.Decimal,5),
					new SqlParameter("@FAllowanceAmount", SqlDbType.Decimal,13),
					new SqlParameter("@FPolicyID", SqlDbType.NVarChar,50),
					new SqlParameter("@FIssueID", SqlDbType.NVarChar,50),
					new SqlParameter("@FFinancePropNo", SqlDbType.NVarChar,6),
                    new SqlParameter("@FStatus", SqlDbType.NVarChar,6)};
                parameters[0].Value = model.FTaxAuditId;
                parameters[1].Value = model.FYear;
                parameters[2].Value = model.FTaxClassAllowanceNo;
                parameters[3].Value = model.FBaseAmount;
                parameters[4].Value = model.FAllowanceType;
                parameters[5].Value = model.FInnerRate;
                parameters[6].Value = model.FOuterRate;
                parameters[7].Value = model.FAllowanceAmount;
                parameters[8].Value = model.FPolicyID;
                parameters[9].Value = model.FIssueID;
                parameters[10].Value = model.FFinancePropNo;
                parameters[11].Value = model.FStatus;
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters;
                cmdList.Add(cmds);
            }

            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }
          
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void DelToIssue(Model.TaxAuditPolicyEval model)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();

            cmds = new CommandInfo();
            strSql = new StringBuilder();
            strSql.Append("update fund.t_TaxAuditPolicyEval set ");
            strSql.Append("FIssueID=@FIssueID,");
            strSql.Append("FStatus=2");
            strSql.Append(" where FTaxAuditId=@FTaxAuditId and FYear=@FYear and FTaxClassAllowanceNo=@FTaxClassAllowanceNo ");
            SqlParameter[] parameters = {
					new SqlParameter("@FIssueID", SqlDbType.NVarChar,50),
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50),
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,20)};
            parameters[0].Value = DBNull.Value;
            parameters[1].Value = model.FTaxAuditId;
            parameters[2].Value = model.FYear;
            parameters[3].Value = model.FTaxClassAllowanceNo;
            cmds.CommandText = strSql.ToString();
            cmds.Parameters = parameters;
            cmdList.Add(cmds);

            if (model.FIssueID != null && model.FIssueID != "")
            {
                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append("delete from fund.t_AllowanceIssueEntry ");
                strSql.Append(" where FIssueID=@FIssueID and FTaxClassAllowanceNo=@FTaxClassAllowanceNo and NSRDZDAH=@NSRDZDAH");
                SqlParameter[] parameters2 = {
					new SqlParameter("@FIssueID", SqlDbType.NVarChar,50)	,	
                    new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,20)	,	
                    new SqlParameter("@NSRDZDAH", SqlDbType.Decimal,20)		};
                parameters2[0].Value = model.FIssueID;
                parameters2[1].Value = model.FTaxClassAllowanceNo;
                parameters2[2].Value = model.NSRDZDAH;
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters2;
                cmdList.Add(cmds);
            }

            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public void AddToIssue(List<Model.TaxAuditPolicyEval> taxAuditPolicyEvalList)
        {
            StringBuilder strSql = new StringBuilder();
            List<CommandInfo> cmdList = new List<CommandInfo>();
            CommandInfo cmds = new CommandInfo();
            foreach (Model.TaxAuditPolicyEval model in taxAuditPolicyEvalList)
            {
                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append("update fund.t_TaxAuditPolicyEval set ");
                strSql.Append("FIssueID=@FIssueID,");
                strSql.Append("FStatus=3 ");
                strSql.Append(" where FTaxAuditId=@FTaxAuditId and FYear=@FYear and FTaxClassAllowanceNo=@FTaxClassAllowanceNo ");
                SqlParameter[] parameters = {
					new SqlParameter("@FIssueID", SqlDbType.NVarChar,50),
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50),
					new SqlParameter("@FYear", SqlDbType.Decimal,5),
					new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,20)};
                parameters[0].Value = model.FIssueID;
                parameters[1].Value = model.FTaxAuditId;
                parameters[2].Value = model.FYear;
                parameters[3].Value = model.FTaxClassAllowanceNo;
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters;
                cmdList.Add(cmds);

                cmds = new CommandInfo();
                strSql = new StringBuilder();
                strSql.Append(@"  INSERT INTO fund.t_AllowanceIssueEntry (FIssueID,FYear,FTaxClassAllowanceNo,FAllowancePeriodAmt,FAllowanceBalAmt,FFactAllowanceAmt,NSRDZDAH,FStatus)
  SELECT FIssueID,FYear,FTaxClassAllowanceNo,YBTJE,FAllowanceAmount,FAllowanceAmount-YBTJE,NSRDZDAH,0 FROM fund.v_TaxAuditPolicyEval
   ");
                strSql.Append(" where FTaxAuditId=@FTaxAuditId and FYear=@FYear and FTaxClassAllowanceNo=@FTaxClassAllowanceNo ");
                cmds.CommandText = strSql.ToString();
                cmds.Parameters = parameters;
                cmdList.Add(cmds);
            }

            if (cmdList.Count > 0)
            {
                DbHelperSQL.ExecuteSqlTranWithString(cmdList);
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public EnterpriseFund.Model.TaxAuditPolicyEval GetModel(string FTaxAuditId, string FYear, string FTaxClassAllowanceNo)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 a.FTaxAuditId,a.FYear,a.FTaxClassAllowanceNo,FBaseAmount,FAllowanceType,FInnerRate,FOuterRate,FAllowanceAmount,FPolicyID,FIssueID,FFinancePropNo,b.NSRDZDAH from fund.t_TaxAuditPolicyEval a left join fund.t_TaxAuditForm b on a.FTaxAuditId=b.FTaxAuditId ");
            strSql.Append(" where a.FTaxAuditId=@FTaxAuditId and FTaxClassAllowanceNo=@FTaxClassAllowanceNo and a.FYear=@FYear ");
            SqlParameter[] parameters = {
					new SqlParameter("@FTaxAuditId", SqlDbType.NVarChar,50)	,
                    new SqlParameter("@FTaxClassAllowanceNo", SqlDbType.NVarChar,50)	,
                    new SqlParameter("@FYear", SqlDbType.NVarChar,50)	};
            parameters[0].Value = FTaxAuditId;
            parameters[1].Value = FTaxClassAllowanceNo;
            parameters[2].Value = FYear;
            EnterpriseFund.Model.TaxAuditPolicyEval model = new EnterpriseFund.Model.TaxAuditPolicyEval();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public EnterpriseFund.Model.TaxAuditPolicyEval DataRowToModel(DataRow row)
        {
            EnterpriseFund.Model.TaxAuditPolicyEval model = new EnterpriseFund.Model.TaxAuditPolicyEval();
            if (row != null)
            {
                if (row["FTaxAuditId"] != null)
                {
                    model.FTaxAuditId = row["FTaxAuditId"].ToString();
                }
                if (row["FYear"] != null && row["FYear"].ToString() != "")
                {
                    model.FYear = decimal.Parse(row["FYear"].ToString());
                }
                if (row["FTaxClassAllowanceNo"] != null)
                {
                    model.FTaxClassAllowanceNo = row["FTaxClassAllowanceNo"].ToString();
                }
                if (row["FBaseAmount"] != null && row["FBaseAmount"].ToString() != "")
                {
                    model.FBaseAmount = decimal.Parse(row["FBaseAmount"].ToString());
                }
                if (row["FAllowanceType"] != null)
                {
                    model.FAllowanceType = row["FAllowanceType"].ToString();
                }
                if (row["FInnerRate"] != null && row["FInnerRate"].ToString() != "")
                {
                    model.FInnerRate = decimal.Parse(row["FInnerRate"].ToString());
                }
                if (row["FOuterRate"] != null && row["FOuterRate"].ToString() != "")
                {
                    model.FOuterRate = decimal.Parse(row["FOuterRate"].ToString());
                }
                if (row["FAllowanceAmount"] != null && row["FAllowanceAmount"].ToString() != "")
                {
                    model.FAllowanceAmount = decimal.Parse(row["FAllowanceAmount"].ToString());
                }
                if (row["FPolicyID"] != null)
                {
                    model.FPolicyID = row["FPolicyID"].ToString();
                }
                if (row["FIssueID"] != null)
                {
                    model.FIssueID = row["FIssueID"].ToString();
                }

                if (row["FFinancePropNo"] != null)
                {
                    model.FFinancePropNo = row["FFinancePropNo"].ToString();
                }
                if (row.Table.Columns.Contains("FFinancePropName"))
                {
                    if (row["FFinancePropName"] != null)
                    {
                        model.FFinancePropName = row["FFinancePropName"].ToString();
                    }
                }

                if (row.Table.Columns.Contains("FEnterprisePropName"))
                {
                    if (row["FEnterprisePropName"] != null)
                    {
                        model.FEnterprisePropName = row["FEnterprisePropName"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("FAllowanceName"))
                {
                    if (row["FAllowanceName"] != null)
                    {
                        model.FAllowanceName = row["FAllowanceName"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("FTaxClassAllowanceName"))
                {
                    if (row["FTaxClassAllowanceName"] != null)
                    {
                        model.FTaxClassAllowanceName = row["FTaxClassAllowanceName"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("NSRSBH"))
                {
                    if (row["NSRSBH"] != null)
                    {
                        model.NSRSBH = row["NSRSBH"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("NSRBM"))
                {
                    if (row["NSRBM"] != null)
                    {
                        model.NSRBM = row["NSRBM"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("NSRMC"))
                {
                    if (row["NSRMC"] != null)
                    {
                        model.NSRMC = row["NSRMC"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("NSRDZDAH"))
                {
                    if (row["NSRDZDAH"] != null)
                    {
                        model.NSRDZDAH = row["NSRDZDAH"].ToString();
                    }
                }
                if (row.Table.Columns.Contains("scounts"))
                {
                    if (row["scounts"] != null && row["scounts"].ToString() != "")
                    {
                        model.scounts = decimal.Parse(row["scounts"].ToString());
                    }
                }

                if (row.Table.Columns.Contains("se"))
                {
                    if (row["se"] != null && row["se"].ToString() != "")
                    {
                        model.se = decimal.Parse(row["se"].ToString());
                    }
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetTaxAuditEntryListByFIssueID(string issueID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT FTaxAuditId,FTaxClassAllowanceNo,SUM(FAdjustAmount) as FAdjustAmount FROM fund.v_TaxAuditEntry WHERE FTaxAuditId IN (
SELECT FTaxAuditId FROM fund.t_TaxAuditPolicyEval WHERE FIssueID=" + issueID + @") GROUP BY FTaxAuditId,FTaxClassAllowanceNo
");
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetTaxAuditPolicyEvalListByFIssueID(string issueID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT  a.FTaxAuditId ,
        a.FYear ,
        FTaxClassAllowanceNo ,
        FBaseAmount ,
        FInnerRate ,
        FOuterRate ,
        FAllowanceAmount ,
        a.FFinancePropNo,b.FFinancePropShortName as FFinancePropName,a.NSRDZDAH,a.NSRMC,a.nsrbm FROM fund.v_AllowanceCalcManage a 
        LEFT JOIN fund.t_FinanceProp b ON a.FFinancePropNo = b.FFinancePropNo
     WHERE FIssueID='" + issueID + "' and evalFStatus<>9");
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllowanceIssueEntryListByFIssueID(string issueID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT  FAllowanceIssueEntryID ,
        FIssueID ,
        FYear ,
        FTaxClassAllowanceNo ,
        FAllowancePeriodAmt ,
        FAllowanceBalAmt ,
        FFactAllowanceAmt,
        NSRDZDAH ,
        FAllowanceFileEntryID FROM fund.t_AllowanceIssueEntry WHERE FIssueID='" + issueID + "'");
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select a.FTaxAuditId,a.FYear,a.FTaxClassAllowanceNo,a.FBaseAmount,a.FAllowanceType,a.FInnerRate,a.FOuterRate,a.FAllowanceAmount,a.FPolicyID,a.FIssueID,a.FFinancePropNo, f.FFinancePropShortName as FFinancePropName,ISNULL(b.scounts,0) AS scounts ");
            strSql.Append(" FROM fund.t_TaxAuditPolicyEval a LEFT JOIN fund.t_FinanceProp f ON a.FFinancePropNo=f.FFinancePropNo ");
            strSql.Append(" LEFT JOIN (SELECT COUNT(*) AS scounts,FTaxAuditId,FTaxClassAllowanceNo FROM fund.t_TaxAuditAdjust GROUP BY FTaxAuditId,FTaxClassAllowanceNo) AS  b ON a.FTaxAuditId = b.FTaxAuditId AND a.FTaxClassAllowanceNo = b.FTaxClassAllowanceNo");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetQueryList(string strWhere)
        { 
            StringBuilder strSql = new StringBuilder();
            strSql.Append(@"SELECT a.*,NSRSBH,NSRDZDAH,NSRBM,t1.NSRMC,FTaxClassAllowanceName,FAllowanceName,FAllowanceType,FBaseAmount,a.FInnerRate,FOuterRate,a.FAllowanceAmount,z.FFinancePropShortName AS FFinancePropName,x.FEnterprisePropName,se from  fund.t_TaxAuditPolicyEval a
      left join
     (select NSRSBH,NSRBM,fund.t_TaxAuditForm.NSRMC,fund.t_TaxAuditForm.FTaxAuditId from fund.t_TaxAuditForm left join  ltais.DJ_NSRXX on fund.t_TaxAuditForm.NSRDZDAH =ltais.DJ_NSRXX.NSRDZDAH) as t1 
      on a.FTaxAuditId=t1.FTaxAuditId
      left join       
      (select FYear,FTaxClassAllowanceNo,FTaxClassAllowanceName from fund.t_TaxClassAllowance) as t2
      on a.FYear=t2.FYear and a.FTaxClassAllowanceNo=t2.FTaxClassAllowanceNo
	left join 
		(select fund.t_AllowanceClass.FAllowanceClassNo,FAllowanceName,FTaxAuditId from fund.t_AllowanceClass left join fund.t_TaxAuditForm on fund.t_TaxAuditForm.FAllowanceClassNo=fund.t_AllowanceClass.FAllowanceClassNo) as t3
		on a.FTaxAuditId=t3.FTaxAuditId
		LEFT JOIN fund.t_FinanceProp z ON a.FFinancePropNo = z.FFinancePropNo
		LEFT JOIN fund.t_TaxAuditForm y ON a.FTaxAuditId=y.FTaxAuditId
		LEFT JOIN fund.t_EnterpriseProp x ON y.FNewEnterprisePropNo = x.FEnterprisePropNo
		LEFT JOIN (SELECT FTaxAuditId,FTaxClassAllowanceNo,SUM(se) AS se FROM fund.t_TaxAudit_SB_ZSXX GROUP BY FTaxAuditId,FTaxClassAllowanceNo) w ON a.FTaxAuditId=w.FTaxAuditId AND a.FTaxClassAllowanceNo=w.FTaxClassAllowanceNo
		");

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" FTaxAuditId,FYear,FTaxClassAllowanceNo,FBaseAmount,FAllowanceType,FInnerRate,FOuterRate,FAllowanceAmount,FPolicyID,FIssueID ");
            strSql.Append(" FROM fund.t_TaxAuditPolicyEval ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM fund.t_TaxAuditPolicyEval ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.FTaxAuditId desc");
            }
            strSql.Append(")AS Row, T.*  from fund.t_TaxAuditPolicyEval T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            SqlParameter[] parameters = {
                    new SqlParameter("@tblName", SqlDbType.VarChar, 255),
                    new SqlParameter("@fldName", SqlDbType.VarChar, 255),
                    new SqlParameter("@PageSize", SqlDbType.Int),
                    new SqlParameter("@PageIndex", SqlDbType.Int),
                    new SqlParameter("@IsReCount", SqlDbType.Bit),
                    new SqlParameter("@OrderType", SqlDbType.Bit),
                    new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
                    };
            parameters[0].Value = "t_TaxAuditPolicyEval";
            parameters[1].Value = "FTaxAuditId";
            parameters[2].Value = PageSize;
            parameters[3].Value = PageIndex;
            parameters[4].Value = 0;
            parameters[5].Value = 0;
            parameters[6].Value = strWhere;	
            return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
        }*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

